<template>
	<view class="page-index">
		<view class="table-box">
			<view :class="[type==item.type?'tableChange':'table']" v-for="(item,index) in tableList" :key="index" @click="tableChange(item)">
				<text>{{item.name}}</text>
				<view class="border"></view>
			</view>
		</view>
		<view class="space" v-if="List.length==0&&listend==true">
			<image src="../../../static/home/noSpace.png" mode=""></image>
			<view class="">
				暂时没有内容～
			</view>
		</view>
		<view class="List" v-for="(item,index) in List" :key="index" @click="details(item)" v-if="List.length!=0">
			<view class="header">
				<image :src="item.avatar" mode="" style="width: 60rpx;height: 60rpx;border-radius: 50%;"></image>
				<view class="box">
					<view class="name">
						{{item.nickname}}
					</view>
					<view class="time">
						{{item.time}}
					</view>
				</view>
			</view>
			<view class="title">
				<view class="title-item1">
					{{item.title}}
				</view>
			</view>
			<!-- 			<view class="address">
				{{item.address}}
			</view> -->
			<view class="remarks">
				{{item.text?item.text:''}}
			</view>
			<view class="image-box">
				<image :src="items" mode="" v-for="(items,indexs) in item.images" :key="indexs" class="image"></image>
			</view>
			<view class="space">
			</view>
		</view>
		<u-loadmore :status="status" v-if="List.length!=0" />
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	export default {
		data() {
			return {
				type: 1,
				page: 1,
				List: [], //列表
				status: 'nomore',
				listend: false,
				tableList: [{
						name: '求租',
						type: 1
					},
					{
						name: '求购',
						type: 2
					}
				]
			}
		},
		onLoad(params) {

			// if (params.type == 'rent') {
			// 	this.type = 1
			// 	uni.setNavigationBarTitle({
			// 		title: '求租求购'
			// 	});
			// } else {
			// 	this.type = 2
			// 	uni.setNavigationBarTitle({
			// 		title: '求购社区'
			// 	});
			// }
			this.getList()
		},
		onReachBottom() {
			this.page += 1
			this.getList()
		},
		methods: {
			details(item) {
				this.$tools.navigate(`/pages/home/rentHome/details/details?id=${item.id}`)
			},
			getList() {
				this.listend = false
				this.status = 'loading'
				let params = {}
				params.type = this.type
				params.page = this.page
				index.getWantList(params).then(res => {
					this.List.push(...res.data.data)
					this.status = 'nomore'
					this.listend = true
				})
				this.status = 'nomore'
			},
			imageSee(item, indexs) {
				uni.previewImage({
					urls: item,
					current: indexs,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			tableChange(item) {
				this.listend = false
				this.type = item.type
				this.page = 1
				console.log(this.listend);
				this.List = []
				this.getList()
			}
		}
	}
</script>

<style scoped lang="scss">
	.page-index {
		font-family: PingFang SC-Medium, PingFang SC;

		.table-box {
			width: 100%;
			background: #ffffff;
			display: flex;
			justify-content: space-between;
			text-align: center;
			height: 60rpx;
			margin-top: 20rpx;
			align-items: center;
			text-align: center;

			.table {
				width: 50%;
				font-size: 30rpx;
			}

			.tableChange {
				// border-bottom: 2rpx solid red;
				font-size: 36rpx;
				font-weight: 700;
				width: 50%;
				color: #006FD0;
				text-align: center;
				position: relative;

				.border {
					height: 0;
					margin-top: 10rpx;
					position: absolute;
					left: 50%;
					transform: translateX(-50%);
					width: 50rpx;
					border: 3rpx solid #006FD0;
				}
			}



		}

		.space {
			text-align: center;
		}

		.List {
			padding: 20rpx 42rpx;
			background: #FFFFFF;

			.header {
				display: flex;
				justify-content: flex-start;
				margin-bottom: 18rpx;
				align-items: center;

				.box {
					margin-left: 16rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					padding: 8rpx;

					.name {
						font-size: 28rpx;
						font-weight: 700;
						color: #333333;
						line-height: 38rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 28rpx;
						opacity: 0.6;
					}
				}
			}

			.title {
				font-size: 32rpx;
				font-weight: 700;
				color: #333333;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				display: flex;
				justify-content: space-between;

				.title-item1 {
					width: 540rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}


			}

			.address {
				padding: 8rpx 0;
				font-size: 26rpx;
				font-weight: 400;
				color: #9E9E9E;
			}

			.remarks {
				padding: 16rpx 0;
				font-size: 24rpx;
				font-weight: 400;
				color: #202020;
			}

			.image-box {
				// padding: 24rpx 0;
				// border-top: 2rpx solid #EAEAEA;

				.image {
					width: 200rpx;
					height: 155rpx;
					border-radius: 24rpx;
					margin-left: 20rpx;
				}

				.image:nth-child(1) {
					margin-left: 0;
				}
			}


			.space {
				height: 20rpx;
				background: #f8f8f8;
				margin: 0rpx -42rpx;
				margin-top: 10rpx;
			}
		}

	}
</style>
